<?php
session_start();
$username = $_SESSION["user"];
$link = mysqli_connect('localhost', 'root', '123', 'Dress', '3306');
mysqli_query($link,"set names 'utf8'");
$sql = "select * from user where username = '$username'";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_array($result);
$name = !empty($_POST['name']) ? $_POST['name'] : $row[2];
$age = !empty($_POST['age']) ? $_POST['age'] : $row[3];
$sex = !empty($_POST['sex']) ? $_POST['sex'] : $row[6];
$phone = !empty($_POST['phone']) ? $_POST['phone'] : $row[5];
$address = !empty($_POST['address']) ? $_POST['address'] : $row[4];
if(isset($_POST["revise"]) && $_POST["revise"] == "修改") {
    mysqli_query($link,"update user set realname='$name',age='$age',sex='$sex',phonenum='$phone',address='$address' where username = '$username'");
    echo "<script>alert('修改成功！'); history.go(-1); </script>";
}
?>